#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
struct ListNode {
    int val;
    struct ListNode* next;
};

struct ListNode* reverseList(struct ListNode* head) 
{
    struct ListNode* p=head->next;
    struct ListNode* s=p;
    head->next = NULL;
    while (p!=NULL)
    {
        s = p->next;
        p->next = head;
        head = p;
        p = s;
    }
    return head;
    
}
int main()
{
    struct ListNode* head = (struct ListNode*)malloc(sizeof(struct ListNode));
    head->next = NULL;
    struct ListNode* p1 = head;
    for (int i = 1; i <= 5; i++)
    {
        struct ListNode* p2 = (struct ListNode*)malloc(sizeof(struct ListNode));
        scanf("%d",& p2->val);
        p1->next = p2;
        p2->next = NULL;
        p1 = p2;
    }
    struct ListNode* p3 = reverseList(head);
    for (int i = 1; i <= 5; i++)
    {
        printf("%d ", p3->val);
        p3 = p3->next;
    }
    return 0;
}
